package org.celstec.mobilegame.gamaray;

import java.util.Vector;

//import org.celstec.mobilegame.locatory.Card;
//import org.celstec.mobilegame.locatory.CardLocation;

public class Dimension {
//	public static String url = "http://celstec1.appspot.com/locatory";
//	public static String url = "http://localhost:8080/locatory";
//	public static String baseUrl = "http://celstec1.appspot.com/";
	public static String baseUrl = "http://localhost:8080/";

//	private String g;
	private String p;
//	public CardLocation tabooCard;


	Vector<Asset> assetVector = new Vector<Asset>();
	Vector<Feature> featureVector = new Vector<Feature>();
	Vector<Overlay> overlayVector = new Vector<Overlay>();
	
	private String refreshURI;
	public Dimension( String p){
		this.p = p;
	}
	
	public Dimension( String p, String refreshURL){
		this.p = p;
		this.refreshURI=refreshURL;
	}
	
	public void add(Asset a) {
		assetVector.add(a);
	}
	
	public void add(Vector<Asset> assets){
		for (int i=0;i<assets.size();i++){
			add(assets.get(i));
		}
		
	}
	
	public void add(Overlay o) {
		overlayVector.add(o);
	}
	
	public void add(Feature f) {
		featureVector.add(f);
	}
	
	public void removeCardFeatures(){
		for (int i = featureVector.size()-1; i >=0; i--) {
			System.out.println("check: "+featureVector.get(i).id);

			if (featureVector.get(i).id.startsWith("cl_")) {
				System.out.println("delete: "+featureVector.get(i).id);
				featureVector.remove(featureVector.get(i));
			}
		}
	}

	public String generateDimensionXml() {
		String ret = "";

		ret += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
		ret += "<dimension version=\"1.0\">\n";
		ret += " <name>Stefaan Dimension</name>\n";
		ret += " <relativeAltitude>true</relativeAltitude>\n";
		if (refreshURI==null){
			ret += " <refreshUrl>" + baseUrl + "locatory?p="+p+"</refreshUrl>\n";
		} else {
			ret += " <refreshUrl>" + refreshURI+"</refreshUrl>\n";

		}
		ret += " <refreshTime><validFor>30000</validFor></refreshTime>\n";
		ret += " <refreshDistance><validWithinRange>10</validWithinRange></refreshDistance>\n";
		ret += getAssets();
		ret += getFeatures();
		ret += getOverlays();
		ret += "</dimension>\n"; 
		return ret;

	}

	public String getAssets() {
		String ret = " <assets>\n";
		for (int i = 0; i < assetVector.size(); i++) {
			
			ret += assetVector.get(i).toXml();
		}
		ret += " </assets>\n";
		return ret;
	}
	
	public String getFeatures() {
		String ret = " <features>\n";
		for (int i = 0; i < featureVector.size(); i++) {
			
			ret += featureVector.get(i).toXml(baseUrl + "locatory?p="+p);
		}
		ret += " </features>\n";
		return ret;

	}
	
	public String getOverlays() {
		String ret = " <overlays>\n";
		for (int i = 0; i < overlayVector.size(); i++) {
			
			ret += overlayVector.get(i).toXml(baseUrl + "locatory?p="+p);
		}
		ret += " </overlays>\n";
		return ret;

	}

}
